import { Pageable, Pagination } from '@/types/global'
import { TenantDto, TenantParam, TenantVo } from '@/types/modules/system'
import axios from 'axios'

const contentPath = '/system/tenant'

export function create(tenant: TenantDto) {
  return axios.post<boolean>(`${contentPath}`, tenant)
}

export function update(tenant: TenantDto) {
  return axios.put<boolean>(`${contentPath}`, tenant)
}

export function grantAuthority(tenantId: string, authoritiesId: number[]) {
  return axios.put<boolean>(`${contentPath}/grant/${tenantId}/authority/`, authoritiesId)
}

export function setUpAdmin(tenantId: string, username: string) {
  return axios.put<boolean>(`${contentPath}/${tenantId}/admin/${username}/setup`)
}

export function deleteById(id: number) {
  return axios.delete<boolean>(`${contentPath}/${id}`)
}

export function findById(id: number) {
  return axios.get<TenantVo>(`${contentPath}/${id}`)
}

export function listWithPagination(pageable: Pageable, param: TenantParam) {
  return axios.get<Pagination<TenantVo>>(`${contentPath}/pagination`, {
    params: {
      ...pageable,
      ...param
    }
  })
}

// 租戶列表
export function list() {
  return axios.get<TenantVo[]>(`${contentPath}/list`)
}

export function findIdListByTenantId(tenantId: string) {
  return axios.get<number[]>(`${contentPath}/tenant/${tenantId}`)
}
